<template>
  <div>
    <van-sticky>
    <div>
        <van-nav-bar  title="网易严选" left-arrow>
            <template #left>
                <van-icon name="wap-home-o" size="30" color="#a0a0a0" @click="toHome"/>
            </template>
            <template #right>
                <van-icon name="search" size="30" color="#a0a0a0" @click="toSearch"/>
                <div style="width: 15px;"></div>
                <van-icon name="shopping-cart-o" size="30" color="#a0a0a0" @click="toCart"/>
            </template>
        </van-nav-bar>
    </div>
    <div>
        <van-tabs v-model:active="active" sticky  @click-tab="changeNav(active)">
            <van-tab v-for="(cate2,index) in category2Val" :title="cate2.name" :key="index">
                <!-- <div class="tabItem"> -->
            </van-tab>
        </van-tabs>   
    </div>
    </van-sticky>
         <div class="box">
            <div class="content1" v-for="list in sortList" :key="list.id"  @click="toDetail(list.id)">
                <div class="contentImg">
                    <img  class="CImg1" :src="list.listPicUrl" alt="" />
                    <img class="CImg2" :src="list.topLogo.logoUrl" alt="">
                </div>
                <div class="title">
                    <span class="name">
                        <span v-for="(img,index) in list.preLogo" :key="index">
                        <img class="listImg" alt="" :src="img.logoUrl">
                        </span>
                            {{ list.name }}
                        </span>
                </div>
                <div class="price">
                    <span class="yuan">￥</span>
                        <span class="newPrice">{{ list.finalPriceInfoVO.priceInfo.finalPrice && list.finalPriceInfoVO.priceInfo.finalPrice.price}}</span>
                        <span class="lodYuan"><del>{{ list.sortOriginPrice }}</del></span>
                </div>
                <div class="footer">
                    <div class="left">
                        限时优惠
                    </div>
                    <div class="right" v-if="list.finalPriceInfoVO.banner?.content">
                            {{ list.finalPriceInfoVO.banner?.content }}
                    </div>
                </div>
             </div>
                        <!-- </div> -->
        </div>
   
  </div>
</template>
<script lang="ts">
import {defineComponent} from 'vue';
import { useRouter } from 'vue-router';
export default defineComponent({
  name: 'SortList'
})
</script>
<script setup lang="ts">
import { ref } from 'vue';
import { Tab, Tabs ,Icon,Sticky} from 'vant';
import {reqSortDataList} from '@/api/modules/sort'
import type{category2Value} from '@/api/modules/sort' 
const active = ref(0);
let router = useRouter()
//categoryId的接收
let listId = ref()
listId.value = router.currentRoute.value.query.categoryId;
//subCategoryId的接收
let listSuperCategoryId =ref()
listSuperCategoryId.value = router.currentRoute.value.query.subCategoryId;
//categoryType的接收
let listCategoryType = ref()
listCategoryType.value = router.currentRoute.value.query.categoryType;
let sortList = ref()
let category2Val = ref<category2Value[]>([])
let currentId = ref()
async function getSortListData(){
    try {
       const result = await reqSortDataList(listId.value,listSuperCategoryId.value,listCategoryType.value)
       sortList.value = result.categoryItems.itemList
       category2Val.value = result.categoryL2List
       currentId.value = result.categoryL2List
    } catch (error) {
        console.log(error);
    }

}
getSortListData()

const changeNav =async (index : number)=>{
    // const res = await getSortListData()
    listSuperCategoryId.value = category2Val.value[index].id
    await getSortListData()
    router.push({
        path:'/item/cateList/sortList',
        query:{ 
            subCategoryId:category2Val.value[index].id
        }
    })
    

}

//去详情
const toDetail = (id:number)=>{
  router.push({
    path:'/item/detail',
    query:{
      id
    }
  })
  
}
//去search
const toSearch = ()=>{
  router.push({
    path:'/search'
  })
}

//去首页
const toHome  = ()=>{
  router.push({
    path:'/'
  })
}

//去购物车
const toCart = ()=>{
  router.push({
    path:'/item/cart'
  })
}
</script>
<style lang="less" scoped>
.tabItem{
    margin-top: 10px;
}
.box {
  display: flex;
  justify-content: space-between;
  padding: 0px 10px 15px 10px;
  flex-wrap: wrap;
}

.content1 {
  display: flex;
  flex-direction: column;
  height: 275px;
  justify-content: space-between;
  margin-top: 20px;

  .contentImg {
    position: relative;
    .CImg1 {
      width: 172.5px;
      height: 172.5px;
      border-radius: 10px;
    }
    .CImg2{
        width: 35px;
        height: 18px;
        position: absolute;
        top: 5px;
        right: 5px;
    }
  }

  .title {
    display: flex;
    font-size: 16px;
    width: 172.5px;
    overflow: hidden;
    text-overflow: ellipsis;
    -webkit-box-orient: vertical;

    .listImg {
      width: 15px;
      height: 15px;
    }

    .name {
      font-size: 14px;
    }
  }

  .price {
    display: flex;
    align-items: center;

    .yuan {
      font-size: 10px;
      color: rgb(250, 30, 50);
      font-weight: 900;
    }

    .newPrice {
      color: rgb(250, 30, 50);
      font-size: 16px;
      font-weight: 900;
    }

    .lodYuan {
      font-size: 10px;
    }
  }

  .footer {
    display: flex;
    align-items: center;
    width: 172.5px;

    .left {
      font-size: 12px;
      color: #fff;
      font-weight: 900;
      width: 60px;
      background-color: #fa1e32;
      height: 20px;
      text-align: center;
      line-height: 20px;
      border-radius: 20px;
    }

    .right {
      font-size: 10px;
      height: 20px;
      color: rgb(250, 30, 50);
      background-color: #ffe9eb;
      flex: 1;
      text-align: center;
      line-height: 22px;
      border-radius: -20px 0 0 -20px;
    }
  }
}
</style>